package com.victor.config;

import com.victor.common.constant.Const;
import com.victor.config.properties.VictorProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;

@Configuration

public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
    @Resource
    protected VictorProperties victorProperties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //addResourceHandler是指你想在url请求的路径
        //addResourceLocations是图片存放的真实路径
        String filePath = victorProperties.getFileUploadPath();
        registry.addResourceHandler("/" + Const.FILE_PREFIX + "/**").addResourceLocations("file:" + filePath);
        super.addResourceHandlers(registry);
    }
}